﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls.Primitives;
using System.Windows;

namespace FlowDesigner.Controll
{
    public class CustomUniformGrid : UniformGrid
    {
        public double FirstColumnWidth { get; set; } = 200;

        //protected override Size MeasureOverride(Size constraint)
        //{
        //    // 子控件的尺寸总和
        //    double totalWidth = 0;
        //    double totalHeight = 0;

        //    // 遍历所有子控件并测量它们
        //    foreach (UIElement child in InternalChildren)
        //    {
        //        if (child != null)
        //        {
        //            // 测量每个子控件
        //            child.Measure(constraint);

        //            // 获取子控件的所需尺寸
        //            Size childSize = child.DesiredSize;

        //            totalWidth += childSize.Width;  // 累加宽度
        //            totalHeight = Math.Max(totalHeight, childSize.Height);  // 取最大的高度
        //        }
        //    }

        //    // 返回根据子控件的尺寸计算出的总尺寸
        //    return new Size(totalWidth, totalHeight);
        //}

        //protected override Size ArrangeOverride(Size arrangeSize)
        //{
        //    if (Columns <= 0 || Rows <= 0)
        //        return base.ArrangeOverride(arrangeSize);

        //    double remainingWidth = arrangeSize.Width - FirstColumnWidth;
        //    double columnWidth = remainingWidth / (Columns - 1);
        //    double rowHeight = arrangeSize.Height / Rows;

        //    int childIndex = 0;

        //    // 安排每个子控件
        //    foreach (UIElement child in InternalChildren)
        //    {
        //        if (child == null)
        //            continue;

        //        int row = childIndex / Columns;
        //        int column = childIndex % Columns;

        //        // 第一列
        //        if (column == 0)
        //        {
        //            child.Arrange(new Rect(0, row * rowHeight, FirstColumnWidth, rowHeight));
        //        }
        //        else
        //        {
        //            child.Arrange(new Rect(FirstColumnWidth + (column - 1) * columnWidth, row * rowHeight, columnWidth, rowHeight));
        //        }

        //        childIndex++;
        //    }

        //    return arrangeSize;
        //}
    }

}
